import { ref } from 'vue'
import { adapter, request } from '@/request'
import { baixingAccountByGet } from '@/core/api/account'
import type { Pagination, RequestWrapper, WithTotalSize } from '@/core/interfaces/common'

interface Params extends Pagination {
  proxyId: number
  name: string
  bxProxyId: number
}

export interface BaixingAccount {
  id: number
  proxyId: number
  name: string
  bxProxyId: number
  createTime: string
}

export default function getBaixingAccount() {
  const service = adapter<RequestWrapper<WithTotalSize<Record<'bxAccounts', BaixingAccount[]>>>>(request)
  const loading = ref(false)
  const response = ref<WithTotalSize<Record<'bxAccounts', BaixingAccount[]>>>()

  const fetch = (params: Partial<Params>) => {
    const { url, method } = baixingAccountByGet()
    loading.value = true

    return service({
      config: {
        url,
        method,
        params
      },
      callback: (res) => {
        response.value = res.data.data
      },
      error: (err) => {
        console.log(err)
      },
      done: () => {
        loading.value = false
      }
    })
  }

  return [response, fetch, loading] as const
}
